#!/usr/bin/perl
#atalk_setting.cgi

require './mdmjobs-lib.pl';
&ReadParse();

&header($text{'atalk_detail'}, "", "index", 0, 1,undef,undef);
print "<form action=mdm_atalk.cgi method=post onsubmit='return checkselect(\"$text{'err_nomember'}\");'>\n";
print "<table class=mode1 border=0 cellspacing=0 cellpadding=0>\n";
print "<tr><td>\n";
local $grpinfo=&foreign_call("mdmgroups","get_groupinfo");
local %grpinfo=%$grpinfo;
local @group = split (/,/,$grpinfo{'[group]'});
&select_members(\@group);	
print "</td></tr>\n";

print "<tr><td><table class=mode1 border=0 cellspacing=0 cellpadding=2>\n";
print "<hr align=left width=550>\n";
print "<tr><td><table class=mode1 border=0 cellspacing=0 cellpadding=2>\n";
print "<h4>$text{'index_setatalk'}</h4>\n";
print "$text{'index_setatalkmsg'}<p>\n";
print "</table></td></tr>\n";
print "<tr><td><table class=mode1 border=0 cellspacing=0 cellpadding=4>\n";
print "<tr><td><input type=radio name=setatalk value='start'>&nbsp;<b>$text{'start_atalk'}</b></td></tr>\n";
print "<tr><td><input type=radio name=setatalk value='stop'>&nbsp;<b>$text{'stop_atalk'}</b></td></tr>\n";
print "<tr><td><input type=radio name=setatalk value='restart'>&nbsp;<b>$text{'restart_atalk'}</b></td></tr>\n";
print "<tr><td><input type=radio checked name=setatalk value='conf'>&nbsp;<b>$text{'conf_atalk'}</b></td></tr>\n";
print "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;<input type=checkbox name=checkatalkguest value='check' onclick=\"return checkguest();\">&nbsp;$text{'afp_allowguest'}</td>\n";
printf "<td><select %s name=guestsel>\n",($in{'checkatalkguest'} eq "check")? "":"disabled";
print "<option value='yes'>$text{'allow_guest'}\n";
print "<option seleted value='no'>$text{'ban_guest'}\n";
print "</select></td> </tr>\n";
printf "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;<input type=checkbox name=checkatlktime value='check' onclick=\"return checktime();\">&nbsp;$text{'afp_timeout'}</td><td><input %s name=afp_timeout value=0></td></tr>\n",($in{'checkatalktime'} eq "check")? "":"disabled";
printf "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;<input type=checkbox value='check' name=checkatalklink onclick=\"return checklink();\">&nbsp;$text{'afp_session'}</td><td><input %s name=afp_session value=0></td></tr>\n",($in{'checkatalklink'} eq "check")? "":"disabled";

print "</table></td><tr><table class=mode1 border=0 cellspacing=4 cellpadding=4>\n";
print "<br><tr><input type=submit class=button1 value=\"$text{'index_submit'}\"></table></tr>\n";
print "</table></td></tr>\n";

print "</table></form>\n";
print <<EOF;
<script>
function checkguest()
{
	if (document.forms[0].checkatalkguest.checked){
		document.forms[0].guestsel.disabled = false;
	}else{
		document.forms[0].guestsel.disabled = true;
	}
}

function checktime()
{
	if (document.forms[0].checkatlktime.checked){
		document.forms[0].afp_timeout.disabled = false;
	}else{
		document.forms[0].afp_timeout.disabled = true;
	}
}

function checklink()
{
	if (document.forms[0].checkatalklink.checked){
		document.forms[0].afp_session.disabled = false;
	}else{
		document.forms[0].afp_session.disabled = true;
	}	
}

function checkselect(alertmessg1)
{
	if(document.forms[0].memberlist.options.length == 0){
		alert(alertmessg1);
		return false;
	}
	
	if(!confirm("$text{'msg_confirm'}")){
                return false;
        }
	
	if(document.forms[0].listinput.value == ""){
		if(document.forms[0].memberlist.options.length > 0){
			document.forms[0].listinput.value = document.forms[0].memberlist.options[0].text;
		}else{
			document.forms[0].listinput.value = "";
		}	

		for(i = 1; i < document.forms[0].memberlist.options.length; i++){
			document.forms[0].listinput.value += "," + document.forms[0].memberlist.options[i].text;
		}
	}
}
</script>
EOF

&footer("index.cgi", $text{'index_title'});
1;
